package br.com.sol.persistencia;

import java.util.List;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import br.com.sol.persistencia.controle.DatabaseOpenHelper;

public abstract class DAO <T>{
	
	protected SQLiteDatabase database;
	protected DatabaseOpenHelper dbOpenHelper;
	private static final String DB_NAME = "socialOpenLife";
	
	public DAO(Context context) {
		dbOpenHelper = new DatabaseOpenHelper(context, DB_NAME, null, 1);
	}
	
	public abstract long insert(T obj);
	public abstract boolean update(T obj);
	public abstract boolean delete(T obj);
	public abstract List<T> select(T obj);
	public abstract Integer getLastId();
	
	public void open(){
		try{
			database = dbOpenHelper.getWritableDatabase();
		}catch(Exception e){
		}
	}
	
	public void close(){
		if (database != null)
			database.close();
	}

}
